package com.controller;


import com.mapper.ConsumerMapper;
import com.pojo.Consumer;
import com.pojo.requestjson.FaceRecognitionRequest;
import com.service.iter.IConsumerService;
import com.service.iter.IFaceServiceImpl;
import com.util.MD5Utils;
import com.util.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * 面控制器
 *
 * @author 蔡文欣
 * @date 2023/06/28 09:31:10
 */
@RestController
@RequestMapping("face/")
public class FaceController {

    /**
     * 人脸服务
     */
    @Autowired
    IFaceServiceImpl faceService;
    /**
     * 用户服务
     */
    @Autowired
    IConsumerService consumerService;
    @Autowired
    ConsumerMapper consumerMapper;

    /**
     * 搜索
     *
     * @param faceRecognitionRequest 人脸识别请求
     * @return {@link Res}
     */
    @PostMapping(value = "/searchFace")
    public Res search(@RequestBody FaceRecognitionRequest faceRecognitionRequest ,HttpServletRequest request) throws Exception {



        return consumerService.queryFace(faceRecognitionRequest);
    }
@PostMapping("byPhoneUpdatePassword/{phone}/{password}")
public Res updatePassword(@PathVariable String phone,@PathVariable String password) throws Exception {
    Res res = new Res();
    password= MD5Utils.getSaltMD5(password);
    int i = consumerMapper.byPhoneUpdatePassword(phone, password);
    if (i>0){
        res.setMsg("修改成功");
        res.setCode(200);
    }else {
        res.setMsg("修改失败");
        res.setCode(400);
    }
    return res;
}



    /**
     * 将面添加到库
     *
     * @param faceRecognitionRequest 人脸识别请求
     * @return {@link Res}
     * @throws Exception 异常
     */
    @PostMapping("/addFace")
    public Res addFaceToLibrary(@RequestBody FaceRecognitionRequest faceRecognitionRequest, HttpServletRequest request) throws Exception {
        return consumerService.addConsumerFace(faceRecognitionRequest);
    }


}
